import { useEffect, useState } from "react";


function useLocalStorage(key, initValue) {
    if (localStorage.getItem(key) !== undefined && localStorage.getItem(key) !== null ) {
        initValue = localStorage.getItem(key)
    }
    const [value, setValue] = useState(initValue)

    
    useEffect(()=>{
        localStorage.setItem(key, value)
    }, [key, value])

    return [value, setValue]
}

export default useLocalStorage;